package PageTable;

import comment.Comment;
import page.Page;
import utils.JdbcUtils;

import javax.swing.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public class DeletePage {
    public static String sql_delete="DELETE FROM page WHERE page_id = ?";
    public static  void delete(){
        JFrame frame=  new JFrame("修改");
        String info = JOptionPane.showInputDialog(frame,"你要删除的文章id号","删除",JOptionPane.WARNING_MESSAGE);
        if(info!=null){
            List<Map<String, Object>> datas= JdbcUtils.JdbcQuery("SELECT * FROM page WHERE page_id = "+info);
            String name=null;
            for(Map<String,Object> map : datas) {
                for (String key : map.keySet()) {
                    if (key.equals("page_name")) name = (String) map.get(key);
                }
            }
            int id = Integer.parseInt(info);
            int yn=JOptionPane.showConfirmDialog(frame, "确认删除该文章？", "确认框", JOptionPane.OK_CANCEL_OPTION);
            if(yn==JOptionPane.YES_OPTION){
                JdbcUtils.JdbcUpdate(sql_delete,id);
                JdbcUtils.JdbcUpdate(Comment.sql_deleteComment_class,name);
                Page.jssum();
                JOptionPane.showMessageDialog(frame, "删除成功");
            }else{
                frame.dispose();
            }
        }
    }
}
